<?php

namespace app\admin\model\xilujob;

use think\Exception;
use think\helper\Arr;
use think\Model;
use traits\model\SoftDelete;
use function fast\array_get;

class ResumeJobIntention extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'xilujob_resume_job_intention';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'job_type_text',
        'fav_category',
        'expect_salary',
        'previous_job_category',
        'fav_city',
        'fav_area',
        'fav_town'
    ];

    public function getJobTypeTextAttr($value, $data) {
        $value = $value ? : array_get($data, 'job_type');
        switch ($value) {
            case 1:
                return '全职';
            case 2:
                return '兼职';
            default:
                return '';
        }
    }

    public function favCategory() {
        return $this->belongsTo(JobCategory::class,'fav_category_id','id',[],'LEFT')->setEagerlyType(0);
    }

    public function expectSalary() {
        return $this->belongsTo('Salary','expect_salary_id','id',[],'LEFT')->setEagerlyType(0);
    }

    public function previousJobCategory() {
        return $this->belongsTo('JobCategory', 'previous_job_category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function favCity() {
        return $this->belongsTo('Area','fav_city_id','id',[],'LEFT')->setEagerlyType(0);
    }

    public function favArea() {
        return $this->belongsTo('Area','fav_area_id','id',[],'LEFT')->setEagerlyType(0);
    }

    public function favTown() {
        return $this->belongsTo('Area','fav_town_id','id',[],'LEFT')->setEagerlyType(0);
    }
}
